﻿var logManager = (function () {
    var logId = "log";
    var leftmenu = "#leftmenu";
    var leftmenu_btn = "leftview_btn";

    var logArray = new Array();
    return {
        init: function () {
            $("#" + leftmenu_btn).button().find("span").removeClass("ui-button-text").end().click(function () {
                var duration = 500;
                if (this.innerHTML.indexOf("&lt;&lt;") != -1) {
                    $(leftmenu).animate({ marginLeft: 0 }, duration);
                    this.innerHTML = this.innerHTML.replace("&lt;&lt;", "&gt;&gt;");
                }
                else {
                    $(leftmenu).animate({ marginLeft: 250 }, duration);
                    this.innerHTML = this.innerHTML.replace("&gt;&gt;", "&lt;&lt;");
                }
            });
        },
        add: function (number, obj, event, arg) {
            var log = new logContext(number, obj, event, arg);
            logArray.push(log);
            //
            var text = config.msg[number.toString()];
            var title = "点击修复该错误!";
            var canvas_w = 20;
            var canvas_h = 20;
            var logTable = $obj(logId);
            var row = logTable.insertRow(0);
            row.insertCell(0).innerHTML = text;
            row.insertCell(1).style.width = "20px";
            //warning
            if (event) {
                var eventCanvas = document.createElement("canvas");
                eventCanvas.width = canvas_w;
                eventCanvas.height = canvas_h;
                eventCanvas.title = title;
                eventCanvas.id = obj.id;
                row.cells[1].appendChild(eventCanvas);
                var animate = Tool.Animate.Text_ShadowAnimate(eventCanvas, 100, null, "!", null, "255,0,0");
                eventCanvas.onclick = (function () {
                    return function () {
                        animate.stop();
                        $obj("log").deleteRow(this.parentNode.parentNode.rowIndex);
                        event.call(obj);
                    }
                })()
                if ($obj(leftmenu_btn).innerHTML.indexOf("&lt;&lt;") != -1) {
                    $obj(leftmenu_btn).click();
                }
            }
            row.insertCell(2).style.width = "20px";
            //help
            if (number >= 11) {
                var helplink = document.createElement("a");
                helplink.href = config.helpPage + "?number=" + number + (arg != null ? arg : "");
                helplink.target = "_blank";
                helplink.appendChild(document.createTextNode("?"));
                row.cells[2].appendChild(helplink);
            }
            var time = new Date();
            row.insertCell(3).innerHTML = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        },
        remove: function (id) {
            var obj = $obj(id);
            if (obj)
                $obj(logId).deleteRow(obj.parentNode.parentNode.rowIndex);
        }
    }
})()
function logContext(number, obj, event, arg) {
    this._number = number;
    this._obj = obj;
    this._event = event;
    this._arg = arg;
}